var year = '';
var month = '';
var day = '';
Component({
  properties: {
    visible: {
      type: Boolean,
      value: false,
      observer(data) {
        this.setData({
          visible: data,
        });
      },
    },
  },
  observers: {
    visible(newVal) {
      if (newVal) {
        this.setData({
          orderStatus: '',
          datetimeText: '',
          mode: '',
          province: '',
          phone: '',
          datetimeVisible: false,
          datetimeVisible1: false,
          datetime: new Date(
            `${new Date().getFullYear()}-${new Date().getMonth() + 1}=${new Date().getDate()}`,
          ).getTime(),
          datetimeText1: '',
          mode1: '',
          datetime1: new Date(
            `${new Date().getFullYear()}-${new Date().getMonth() + 1}=${new Date().getDate()}`,
          ).getTime(),
        });
      }
    },
  },
  data: {
    fillPrice: false,
    orderStatus: '',
    datetimeText: '',
    mode: '',
    datetimeVisible: false,
    datetimeVisible1: false,
    datetime: new Date(`${new Date().getFullYear()}-${new Date().getMonth() + 1}=${new Date().getDate()}`).getTime(),
    datetimeText1: '',
    mode1: '',
    datetime1: new Date(`${new Date().getFullYear()}-${new Date().getMonth() + 1}=${new Date().getDate()}`).getTime(),
    province: '',
    phone: '',
  },
  created() {
    this.children = [];
    this.currentActive = -1;
    this.topRightRadiusItemIndexs = [];
    this.bottomRightRadiusItemIndexs = [];
  },

  methods: {
    onProvinceInput(e) {
      const { value } = e.detail;
      this.setData({
        province: value,
      });
    },
    onPhoneInput(e) {
      const { value } = e.detail;
      this.setData({
        phone: value,
      });
    },
    onVisibleChange(e) {
      this.setData({
        visible: e.detail.value,
      });
    },
    showPicker(e) {
      const { mode } = e?.currentTarget?.dataset;
      this.setData({
        mode,
        [`${mode}Visible`]: true,
      });
    },
    showPicker1(e) {
      const { mode1 } = e?.currentTarget?.dataset;
      this.setData({
        mode1,
        datetimeVisible1: true,
      });
    },
    hidePicker() {
      const { mode } = this.data;
      this.setData({
        [`${mode}Visible`]: false,
      });
    },
    hidePicker1() {
      const { mode1 } = this.data;
      this.setData({
        [`${mode1}Visible`]: false,
      });
    },
    onConfirm(e) {
      const { value } = e?.detail;
      const { mode } = this.data;

      console.log('confirm', value);

      this.setData({
        [mode]: value,
        [`${mode}Text`]: value,
      });

      this.hidePicker();
    },
    onConfirm1(e) {
      const { value } = e?.detail;
      const { mode1 } = this.data;

      this.setData({
        [mode1]: value,
        datetimeText1: value,
      });

      this.hidePicker1();
    },
    onColumnChange(e) {
      console.log('pick', e?.detail?.value);
    },
    onColumnChange1(e) {
      console.log('pick', e?.detail?.value);
    },
    onChange(e) {
      const { value } = e.detail;
      this.setData({
        orderStatus: value,
      });
    },
    onReset() {
      this.setData({
        orderStatus: '',
        datetimeText: '',
        mode: '',
        datetimeVisible: false,
        datetimeVisible1: false,
        datetime: new Date(
          `${new Date().getFullYear()}-${new Date().getMonth() + 1}=${new Date().getDate()}`,
        ).getTime(),
        datetimeText1: '',
        mode1: '',
        province: '',
        phone: '',
        datetime1: new Date(
          `${new Date().getFullYear()}-${new Date().getMonth() + 1}=${new Date().getDate()}`,
        ).getTime(),
      });
      this.triggerEvent('hide', {
        hide: false,
      });
      this.triggerEvent('search', {
        startPlaceTime: this.data.datetimeText,
        endPlaceTime: this.data.datetimeText1,
        province: this.data.province,
        phone: this.data.phone,
      });
      this.hidePicker();
      this.hidePicker1();
    },
    onSubmit() {
      this.triggerEvent('search', {
        startPlaceTime: this.data.datetimeText,
        endPlaceTime: this.data.datetimeText1,
        province: this.data.province,
        phone: this.data.phone,
      });
      this.triggerEvent('hide', {
        hide: false,
      });
      this.hidePicker();
      this.hidePicker1();
    },
  },
});
